package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/yuewen/config"
	"net/http"
	"net/url"
)

type BookGetSpreadListApiService service

type BookGetSpreadListRequest struct {
	ctx         context.Context
	ApiService  *BookGetSpreadListApiService
	appFlag     *string
	type_       *uint
	channelType *uint
	recycle     *uint
	startTime   *uint64
	endTime     *uint64
	page        *uint
}

type BookGetSpreadListResponse struct {
	Code    *int64          `json:"code,omitempty"`
	Message *string         `json:"message,omitempty"`
	Data    *SpreadListData `json:"data,omitempty"`
}

type SpreadListData struct {
	TotalCount *int          `json:"total_count,omitempty"`
	List       []*SpreadInfo `json:"list,omitempty"`
}

type SpreadInfo struct {
	ChannelName       *string `json:"channel_name,omitempty"`
	ChannelId         *int    `json:"channel_id,omitempty"`
	OriginalChannelId *string `json:"original_channel_id,omitempty"`
	ChannelType       *int    `json:"channel_type,omitempty"`
	PageName          *string `json:"page_name,omitempty"`
	AppFlag           *string `json:"appflag,omitempty"`
	AppName           *string `json:"app_name,omitempty"`
	CreateTime        *string `json:"create_time,omitempty"`
	BookId            *string `json:"book_id,omitempty"`
	ChapterId         *string `json:"chapter_id,omitempty"`
	ForceChapter      *int    `json:"force_chapter,omitempty"`
	ForceStyle        *int    `json:"force_style,omitempty"`

	// 公众号参数
	WxworkForceStyle   *int    `json:"wxwork_force_style,omitempty"`
	WxworkForceChapter *int    `json:"wxwork_force_chapter,omitempty"`
	BottomQR           *int    `json:"bottom_QR,omitempty"`
	ShortUrl           *string `json:"short_url,omitempty"`
	// 快应用参数
	ForceDesktop *int    `json:"force_desktop,omitempty"`
	HapUrl       *string `json:"hap_url,omitempty"`
	H5Url        *string `json:"h5_url,omitempty"`
	HttpUrl      *string `json:"http_url,omitempty"`
	ApkUrl       *string `json:"apk_url,omitempty"`

	Url *string `json:"url,omitempty"`

	// 短篇参数
	Path        *string      `json:"path,omitempty"`
	UrlLink     *string      `json:"url_link,omitempty"`
	UrlLinkH5   *string      `json:"url_link_h5,omitempty"`
	WxAppid     *int         `json:"wx_appid,omitempty"`
	TrackingUrl *TrackingUrl `json:"tracking_url,omitempty"`
}

type TrackingUrl struct {
	SiteLabel *string `json:"site_label,omitempty"`
	SiteUrl   *string `json:"site_url,omitempty"`
}

func (r *BookGetSpreadListRequest) AppFlag(appFlag string) *BookGetSpreadListRequest {
	r.appFlag = &appFlag
	return r
}

func (r *BookGetSpreadListRequest) Type(type_ uint) *BookGetSpreadListRequest {
	r.type_ = &type_
	return r
}

func (r *BookGetSpreadListRequest) ChannelType(channelType uint) *BookGetSpreadListRequest {
	r.channelType = &channelType
	return r
}

func (r *BookGetSpreadListRequest) Recycle(recycle uint) *BookGetSpreadListRequest {
	r.recycle = &recycle
	return r
}

func (r *BookGetSpreadListRequest) StartTime(startTime uint64) *BookGetSpreadListRequest {
	r.startTime = &startTime
	return r
}

func (r *BookGetSpreadListRequest) EndTime(endTime uint64) *BookGetSpreadListRequest {
	r.endTime = &endTime
	return r
}

func (r *BookGetSpreadListRequest) Page(page uint) *BookGetSpreadListRequest {
	r.page = &page
	return r
}

func (r *BookGetSpreadListRequest) Execute() (*BookGetSpreadListResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *BookGetSpreadListRequest) ApiSecret(ApiSecret string) *BookGetSpreadListRequest {
	r.ctx = context.WithValue(r.ctx, config.ApiSecret, ApiSecret)
	return r
}

func (r *BookGetSpreadListRequest) Email(Email string) *BookGetSpreadListRequest {
	r.ctx = context.WithValue(r.ctx, config.Email, Email)
	return r
}

func (r *BookGetSpreadListRequest) WithLog(enable bool) *BookGetSpreadListRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *BookGetSpreadListApiService) Get(ctx context.Context) *BookGetSpreadListRequest {
	return &BookGetSpreadListRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *BookGetSpreadListApiService) getExecute(r *BookGetSpreadListRequest) (*BookGetSpreadListResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/" + cfg.Prefix + "/Book/GetSpreadList"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *BookGetSpreadListResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasAppFlag(r.appFlag); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	if ok, GenericOpenAPIError := hasReqParam(r.type_, "Type"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	if ok, GenericOpenAPIError := hasReqParam(r.channelType, "ChannelType"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	localVarQueryParams.Add("appflag", *r.appFlag)
	localVarQueryParams.Add("type", toString(r.type_))
	localVarQueryParams.Add("channel_type", toString(r.channelType))

	if r.recycle != nil {
		localVarQueryParams.Add("recycle", toString(r.recycle))
	}

	if r.startTime != nil {
		localVarQueryParams.Add("start_time", toString(r.startTime))
	}

	if r.endTime != nil {
		localVarQueryParams.Add("end_time", toString(r.endTime))
	}

	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
